package com.sichen.search.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * 商城的session配置文件
 * <p>Created with IntelliJ IDEA.
 * <p>Author: 思尘
 * <p>Created time: 2022-09-22 11:06
 * <p>Version: V1.0
 */
@Configuration
public class MallSessionConfig {

    /**
     * 设置cookie的作用域和cookie的名字
     * @return CookieSerializer
     */
    @Bean
    public CookieSerializer cookieSerializer(){
        DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();
        cookieSerializer.setDomainName("sichen.com");
        cookieSerializer.setCookieName("SICHENSESSION");
        return cookieSerializer;
    }

    /**
     * 使用JackSon的序列化机制
     * @return JackSon的序列化对象
     */
    @Bean
    public RedisSerializer<Object> springSessionDefaultRedisSerializer(){
        return new GenericJackson2JsonRedisSerializer();
    }
}
